package com.gupao.javavip.concurrent;

import java.util.concurrent.TimeUnit;

public class ThreadTest {
    private volatile int value = 0;

    public int getAndIncrement() {
        return ++value;
    }

    public int get() {
        return value;
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadTest test = new ThreadTest();

        for (int i = 0; i < 1000; i++) {
            Thread thread = new Thread(() -> {
                try {
                    TimeUnit.MILLISECONDS.sleep(100);

                    test.getAndIncrement();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            thread.start();
        }

        TimeUnit.SECONDS.sleep(3);
        System.out.println("=========" + test.get());
    }
}
